#!/usr/bin/env ruby

name, email = *ARGV

abort "Usage: script/add_owner [GEM_NAME] [USER_EMAIL]" if name.nil? || email.nil?

ENV["RAILS_ENV"] ||= "production"
require_relative "../config/environment"

user    = User.find_by_email!(email)
rubygem = Rubygem.find_by_name!(name)

authorizer = User.security_user

rubygem.ownerships.create(user_id: user.id, authorizer: authorizer, confirmed_at: Time.current)

puts "#{email} added to #{name}."
